<template>
  <div class="exhibits-box">
    <div class="title_text" ref="titleText">
      <titles :title="props.info.text" />
      <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
      <div style="margin-bottom: 50px; margin-top: 20px">
        <textMax v-if="props.info.remarks" :data="props.info.remarks" :maxLen="101" :tip="''" />
      </div>
    </div>
    <div>
      <div
        ref="exhibitsRightImageList"
        v-if="props.tabDatas.length <= 3"
        class="exhibitsRightImage"
        :style="{
          width: `1180px`,
        }"
      >
        <div
          v-for="item in props.tabDatas"
          :key="item.id"
          class="exhibitsRightImageBox"
          @click="pathInfo(item.id)"
          ref="exhibitsRightImageBox"
          style="cursor: pointer"
        >
          <div class="item-left-img-box">
            <t-image
              fit="cover"
              class="item-left-img"
              :src="$filters.getLinkUrl(item.coverUrl, '?imageView2/1/w/380/h/380/format/webp')"
              alt=""
            />
            <div class="shadow"></div>
          </div>
          <div class="item-heard">
            <div>
              <span class="titleText" :style="{}"> {{ item.name }}</span>
              <div class="line"></div>
            </div>
          </div>
        </div>
      </div>
      <div v-else ref="exhibitsRightImageList" style="position: relative">
        <div ref="arrowBox" class="arrowBox1" style="cursor: pointer">
          <div
            class="arrow-box-left"
            :style="{
              opacity: current === 0 ? '0.3' : '1',
              background: store.styleInfo.shmentColor,
            }"
          >
            <arrowLeft @click="addCruuent(-1)" />
          </div>
        </div>
        <div style="overflow: hidden">
          <div
            ref="exhibitsRightImage"
            class="exhibitsRightImage"
            :style="{
              width: `${400 * props.tabDatas.length}px`,
            }"
            style="overflow-x: scroll; justify-content: flex-start"
          >
            <div
              class="exhibitsRightImageBox"
              ref="exhibitsRightImageBox"
              v-for="item in props.tabDatas"
              :key="item.id"
              @click="pathInfo(item.id)"
              style="cursor: pointer"
            >
              <div class="item-left-img-box">
                <t-image
                  fit="cover"
                  class="item-left-img"
                  :src="$filters.getLinkUrl(item.coverUrl, '?imageView2/1/w/380/h/380/format/webp')"
                  alt=""
                />
                <div class="shadow"></div>
              </div>
              <div class="item-heard">
                <div>
                  <span class="titleText" :style="{}"> {{ item.name }}</span>
                  <div class="line"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div ref="arrowBox2" class="arrowBox2">
          <div
            class="arrow-box-right"
            :style="{
              opacity: current === props.tabDatas.length - 3 ? '0.3' : '1',
              background: store.styleInfo.shmentColor,
            }"
            style="cursor: pointer"
          >
            <arrowRight @click="addCruuent(1)" />
          </div>
        </div>
      </div>
    </div>
    <div
      @click="pathChild"
      :style="{
        fontSize: store.styleInfo.mintitleSize,
        color: '#fff',
      }"
      class="left-btn flex-c-c-c"
    >
      <div class="btn-img">
        <buttonIcon />
      </div>
      <span>查看全部</span>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { onMounted, ref } from 'vue';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import { useProjectStore } from '@/store';
import { useRoute, useRouter } from 'vue-router';
import textMax from '@/components/textMax/textMax.vue';
import arrowLeft from '../publicComponents/components/arrowLeft.vue';
import arrowRight from '../publicComponents/components/arrowRight.vue';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
import { imgEnter, imgLeave } from '@/pages/templatePage/components/Subunit/component/hover';
const router = useRouter();
const route = useRoute();
const store = useProjectStore();
const props = defineProps({
  info: {
    type: Object,
  },
  tabDatas: {
    type: Array,
  },
});

const exhibitsRightImage = ref(null);
const exhibitsRightImageBox = ref(null);
const titleText = ref(null);
const arrowBox = ref(null);
const exhibitsRightImageList = ref(null);
const arrowBox2 = ref(null);
const current = ref(0);
const pathInfo = (e: number) => {
  router.push({
    name: route.meta.loopType ? pathListLoop[2] : pathList[2],
    query: { id: e, moduleId: props.info.id },
  });
};
const addCruuent = (num: number) => {
  if (current.value === 0 && num < 0) {
    return;
  } else if (current.value === props.tabDatas.length - 3 && num > 0) {
    return;
  } else {
    current.value = current.value + num;
    exhibitsRightImage.value.style.transform = `translateX(${-400 * current.value}px)`;
  }
};
onMounted(() => {
  // hover('.titleText', '.line', '.exhibitsRightImageBox', props.tabDatas.length);

  const observer = new IntersectionObserver((entries) => {
    let canTrigger = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码
        titleText.value.classList.add('animation-box');

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (titleText.value) {
        //   titleText.value.classList.remove('animation-box');
        // }
      }
    });
  });
  observer.observe(titleText.value);
  const observer1 = new IntersectionObserver((entries) => {
    let canTrigger1 = true; // 标记是否可以触发
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger1) {
        // console.log('exhibitsRightImageBox', exhibitsRightImageBox.value.length);
        for (let index = 0; index < exhibitsRightImageBox.value.length; index++) {
          setTimeout(() => {
            exhibitsRightImageBox.value[index].classList.add('animation-box2');
          }, 300 * index);
        }
        if (arrowBox.value) {
          setTimeout(() => {
            arrowBox.value.classList.add('animation-box2');
            arrowBox2.value.classList.add('animation-box2');
          }, exhibitsRightImageBox.value.length * 300);
        }
        // 设置一个延迟时间，防止频繁触发
        canTrigger1 = false;
        setTimeout(() => {
          canTrigger1 = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        if (exhibitsRightImageBox.value) {
          for (let i = 0; i < exhibitsRightImageBox.value.length; i++) {
            exhibitsRightImageBox.value[i].classList.remove('animation-box2');
          }
        }
        if (arrowBox.value) {
          arrowBox.value.classList.remove('animation-box2');
          arrowBox2.value.classList.remove('animation-box2');
        }
      }
    });
  });
  observer1.observe(exhibitsRightImageList.value);
});
const pathChild = () => {
  store.setchildModel(props.info);
  store.setCurrent(0);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { childId: props.info.id },
  });
};
</script>

<style lang="less" scoped>
@import './index.less';
.exhibits-box {
  // display: flex;
  // overflow: hidden;
  position: relative;
  // background: #fbf9f6;
  .title_text {
    width: 820px;
    height: 213px;
    height: 100%;
    margin: 0 auto;
  }
  .left-btn {
    margin: 0 auto;
    margin-top: 50px;
  }
  .exhibitsRightImage {
    display: flex;
    transition: all 0.5s;
    justify-content: center;
    align-items: center;
    > div {
      margin-right: 20px;
    }
    > div:last-child {
      margin-right: 0;
    }
  }
  .exhibitsRightImageBox {
    transition: all 0.5s;
    opacity: 0;
    cursor: pointer;
  }
  .exhibitsRightImage::-webkit-scrollbar {
    display: none;
  }
  .item-heard {
    width: 380px;
    // height: 28px;
    padding: 24px 50px;
    text-align: center;
    background-color: #fff;
    > div {
      width: 280px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      font-size: 18px;
      height: 30px;
      line-height: 28px;
      // font-family: SourceHanSerifCN-Bold, SourceHanSerifCN;
    }
  }
}
.arrow-box-right {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  /deep/.iconfonts {
    color: #fff !important;
  }
}
.arrowBox2,
.arrowBox1 {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  position: absolute;
  top: 212px;

  z-index: 101;
  opacity: 0;
  transition: all 0.5s;
  > div {
    width: 32px;
    height: 32px;
    border-radius: 50%;
  }
  /deep/.iconfonts {
    color: #fff !important;
  }
}
.arrowBox2 {
  right: -16px;
}
.arrowBox1 {
  left: -16px;
}
// .arrowBoxRight{
//   width: 32px;
//   height: 32px;
//   // opacity: 0;
// }
.line {
  width: 0px;
  height: 2px;
  background: #000;
  transform: all 0.5s;
  margin-bottom: 15px;
  margin: auto;
}

.shadow {
  width: 380px;
  height: 380px;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}
.item-left-img-box {
  width: 380px;
  height: 380px;
  overflow: hidden;
  transition: all 0.5s;
  position: relative;
  .t-image__wrapper {
    width: 100%;
    height: 100%;
    transition: all 0.5s;
  }
}
.item-left-img-box:hover .shadow {
  background: rgba(0, 0, 0, 0.4);
}
.item-left-img-box:hover .t-image__wrapper {
  transform: scale(1.1);
}
.animation-box {
  animation: slideIn 0.5s forwards;
}
@keyframes slideIn {
  0% {
    padding-top: 194px;
    // transform: translateY(100%); /* 元素初始位置 */
    opacity: 0;
  }
  100% {
    padding-top: 0;
    opacity: 1;
    // transform: translateY(0); /* 元素最终位置 */
  }
}
.animation-box2 {
  animation: slideIn2 1s forwards;
}
@keyframes slideIn2 {
  0% {
    // padding-right: 980px;
    transform: translateX(-10%); /* 元素初始位置 */
    opacity: 0;
  }
  100% {
    opacity: 1;
    transform: translateX(0); /* 元素最终位置 */
  }
}
</style>
